private void Form1_Load(object sender, EventArgs e)
{
treeView1.ShowLines = true;
treeView1.ImageList = imageList1;
SqlConnection con = new SqlConnection("server=.;uid=sa;database=db");
con.Open();
SqlCommand com = new SqlCommand("select * from dbzx", con);
SqlDataReader dr = com.ExecuteReader();
TreeNode nodel = treeView1.Nodes.Add("A", "資訊", 1, 2);
while (dr.Read())
{
TreeNode nodel2 = new TreeNode("資訊1" + dr[1].ToString(), 3, 4);
nodel2.Nodes.Add("A", " 資訊2" + dr[0].ToString(), 5, 6);
nodel.Nodes.Add(nodel2);
}
dr.Close();
con.Close();
treeView1.ExpandAll();
}
把資料庫資料改成節點檔案顯示在treeview中